package com.ogawa.base.base;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.os.Handler;

import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.ogawa.base.utils.AppManager;
import com.ogawa.base.utils.ClipboardUtils;

public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks {
    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        LogUtils.e(activity.getLocalClassName() + " - onActivityCreated");
        AppManager.getAppManager().addActivity(activity);

    }

    @Override
    public void onActivityStarted(Activity activity) {
        LogUtils.i(activity.getLocalClassName() + " - onActivityStarted");

    }


    @Override
    public void onActivityResumed(Activity activity) {
        LogUtils.i(activity.getLocalClassName() + " - onActivityResumed");
        try{
            Handler handler = new Handler(activity.getMainLooper());
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    try{
                        checkClip(activity);
                    }catch (Exception e){

                    }
                }
            }, 500);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onActivityPaused(Activity activity) {
        LogUtils.i(activity.getLocalClassName() + " - onActivityPaused");
    }

    @Override
    public void onActivityStopped(Activity activity) {
        LogUtils.i(activity.getLocalClassName() + " - onActivityStopped");
    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
        LogUtils.i(activity.getLocalClassName() + " - onActivitySaveInstanceState");
    }

    @Override
    public void onActivityDestroyed(Activity activity) {
        KeyboardUtils.hideSoftInput(activity);
        LogUtils.e(activity.getLocalClassName() + " - onActivityDestroyed");
        AppManager.getAppManager().removeActivity(activity);
    }


    public void checkClip(Activity activity) {
        String clipStr = ClipboardUtils.getText(activity).toString();
        LogUtils.e("" + activity.getLocalClassName() + ":" + "剪切版 获取到的剪切版：" + clipStr);
    }




}
